#include "place_view.h"
#include "ui_place_view.h"

PlaceView::PlaceView(QWidget *parent) :
    ViewBase(parent),
    ui(new Ui::PlaceView)
{
    ui->setupUi(this);

    QAction *backSoftkeyAction = new QAction(QString("Back"), this);
    backSoftkeyAction->setSoftKeyRole(QAction::NegativeSoftKey);
    QObject::connect(backSoftkeyAction, SIGNAL(triggered()),
                     this, SLOT(hide()));
    addAction(backSoftkeyAction);
}

PlaceView::~PlaceView()
{
    delete ui;
}


int PlaceView::ProcessRawResult(QByteArray &byte) {
    QImage img = QImage::fromData(byte);
    ui->lblImage->setPixmap(QPixmap::fromImage(img));


  return 0;
}

void PlaceView::IssueRequest() {
  if (handler_) {
    qDebug() << "Requesting Image: " << place_.show_image_url;
    RequestMethod request(this, place_.show_image_url);
    handler_->IssueRequest(request);
  }
}

void PlaceView::SetPlace(place p) {
  place_ = p;
  ui->lblTitle->setText( p.name );
  ui->lblImage->clear();
  ui->lblPhone->setText( p.contact );
  ui->lblTags->setText( p.tags );
  ui->prgStar->setValue(p.star_count);

  QDomDocument doc;
  doc.setContent(p.description);
  QDomElement e = doc.documentElement();

  ui->cmdDetails->setText( e.text().trimmed() );

  doc.setContent(p.address);
  QDomElement er = doc.documentElement();

  ui->cmdAddress->setText( er.text().trimmed() );
}
